home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / Javacup / INGZP26A.TAR / internet / INGZP26A / Location.java < prev    next >
Encoding:
Java Source  |  1996-05-21  |  4.3 KB  |  176 lines

  1. /* $Id: Location.java,v 1.6 1996/03/31 11:43:02 djun Exp djun $
  2.  
  3.    File: Location.java
  4.  
  5.    Defines the class Location, which is the key object for the
  6.    GIS. Each map consists of a bunch of locations; each location is
  7.    embedded in some map.
  8.  
  9.    Author: Djun M. Kim
  10.    Copyright (c) 1996 Djun M. Kim.  All rights reserved.
  11.  
  12.  
  13. */
  14.  
  15. import Map;
  16. import MapError;
  17. import java.net.*;
  18. import java.awt.*;
  19. import java.util.Vector;
  20.  
  21. public class Location extends Object {
  22.  
  23.     protected Map parent;
  24.  
  25.     protected Point     base;        // base coordinate of the location
  26.     protected Region    region;        // perimeter of the region
  27.     protected String    name;        // name of the location
  28.     protected URL     url;        // hyperlink
  29.     protected Map    detail;        // detail map of location
  30.     protected Vector    entrances;    // carriers entering this location 
  31.     protected Vector    exits;        // carriers leaving this location 
  32.     protected Image    mapimg;        // map image of the location
  33.     protected String    infotext;    // text describing the location
  34.     protected Vector    keywords;    // keyword strings used to do lookups
  35.  
  36.     protected boolean     displayable;    // does it make sense to display this location?
  37.  
  38.     protected MapError     error_handler = new MapError();
  39.  
  40.     // Constructor
  41.     Location(Map target, Point p) {
  42.     this.parent = target;
  43.     base = new Point(p.x, p.y);
  44.     name = new String();    
  45.     region = new Region();
  46.     exits = new Vector();
  47.     entrances = new Vector();
  48.     }
  49.  
  50.     // Constructor
  51.     Location(Map target, int x, int y) {
  52.     this(target, new Point(x, y));
  53.     }
  54.  
  55.     /*--------- Accessor Methods -------- */
  56.  
  57.     // base coordinate of the location
  58.     public Point getBase() {return(base);};
  59.     public void setBase(Point p) {base = p;};
  60.  
  61.     // perimeter of the region
  62.     public Region getRegion() {return(region);};
  63.     public void setRegion(Region r) {
  64.     region = r;
  65.     }; 
  66.  
  67.     // name of the location
  68.     public String getName() {
  69.     return(name);
  70.     };
  71.  
  72.     public void setName(String s) {
  73.     name = s;
  74.     parent.registerLocation(s, this);
  75.     parent.registerKeyword(s, this);
  76.     };
  77.  
  78.     // hyperlink;
  79.     public URL getURL() {return(url);};
  80.     // Assume that url's url and u are good...
  81.     public void setURL(String urlstring) {
  82.     try {
  83.         url = new URL(urlstring);
  84.     } catch (java.net.MalformedURLException e) {
  85.         error_handler.display("Malformed URL Exception: " + e.getMessage());
  86.     };
  87.     };
  88.  
  89.  
  90.     // detail map of location
  91.     public Map getDetailMap() {return(detail);};
  92.     public void setDetailMap(Map m) {
  93.     detail = new Map();
  94.     detail = m;
  95.     };
  96.  
  97.     // entrances
  98.     public Vector getEntrances() {return(entrances);};
  99.     public void setEntrances(Vector vec) {entrances = vec;};
  100.     public void addEntrance(Carrier c) {entrances.addElement(c);};
  101.  
  102.     // exits
  103.     public Vector getExits() {return(exits);};
  104.     public void setExits(Vector vec) {exits = vec;};
  105.     public void addExit(Carrier c) {exits.addElement(c);};
  106.  
  107.     // map image of the location ;
  108.     public Image getMapimg() {return(mapimg);};
  109.     // this will have to change...
  110.     public void setMapimg(Image i) {mapimg = i;};
  111.  
  112.     // text describing the location
  113.     public String getInfoText() {return(infotext);};
  114.     public void setInfoText(String s) {
  115.     infotext = new String(s);
  116.     };
  117.     public void appendtoInfoText(String s) {
  118.     if (infotext == null) {
  119.         infotext = new String(s);
  120.     } else {
  121.         infotext = infotext + s + "\n";
  122.         parent.registerKeyword(s, this);
  123.     }
  124.     };
  125.  
  126.     public boolean isDisplayable() {
  127.     return displayable;
  128.     }
  129.     public void setDisplayable(boolean b) {
  130.     displayable = b;
  131.     }
  132.  
  133.     /* --------- Keyword definitions and lookups -----------*/
  134.  
  135.     // array of keyword strings used to do lookups
  136.     public Vector getKeywords() {return(keywords);};
  137.  
  138.     public void initKeywords() {keywords = new Vector();};
  139.  
  140.     public void addKeyword(String keyword) {
  141.     keywords.addElement(keyword);
  142.     parent.registerKeyword(keyword, this);
  143.     };
  144.  
  145. }
  146.  
  147. class Road extends Location {
  148.  
  149.     Road(Map target, int x, int y) {
  150.     super(target, x, y);
  151.     }
  152. }
  153.  
  154.  
  155. class Building extends Location {
  156.  
  157.     Building(Map target, int x, int y) {
  158.     super(target, x, y);
  159.     super.setDisplayable(true);
  160.     }
  161.  
  162.     Building(Map target, Point p) {
  163.     super(target, p);
  164.     super.setDisplayable(true);
  165.     }
  166. }
  167.  
  168. class Park extends Location {
  169.  
  170.     Park(Map target, int x, int y) {
  171.     super(target, x, y);
  172.     super.setDisplayable(true);
  173.     }
  174. }
  175.  
  176.